package com.alibaba.otter.shared.arbitrate.autoconfigure;

import com.alibaba.otter.shared.arbitrate.impl.communication.ArbitrateCommunicationClient;
import com.alibaba.otter.shared.communication.core.CommunicationClient;
import com.alibaba.otter.shared.communication.core.impl.DefaultCommunicationClientImpl;
import com.alibaba.otter.shared.communication.core.impl.dubbo.DubboCommunicationConnectionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class ArbitrateCommunicationConfiguration {

    @Bean(initMethod = "initial",destroyMethod = "destroy")
    public CommunicationClient arbitrateCommunicationClient(){

        DefaultCommunicationClientImpl communicationClient = new DefaultCommunicationClientImpl();
        // 设置连接方式
        DubboCommunicationConnectionFactory dubboCommunicationConnectionFactory = new DubboCommunicationConnectionFactory();
        dubboCommunicationConnectionFactory.setPayload(8388608);
        // 设置dubbo通讯方式
        communicationClient.setFactory(dubboCommunicationConnectionFactory);
        communicationClient.setPoolSize(100);
        return communicationClient;
    }

    @Bean
    public ArbitrateCommunicationClient arbitrateCommunicationDelegateClient(@Qualifier("arbitrateCommunicationClient") CommunicationClient arbitrateCommunicationClient){
        ArbitrateCommunicationClient c = new ArbitrateCommunicationClient();
        c.setDelegate(arbitrateCommunicationClient);
        return c;
    }
}
